﻿
using SmartSapce.ServiceLocation;
using SmartSpace.Core;
using SmartSpace.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SmartSpace.WebApp._console.common
{
    public partial class select_page : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void _ctlBtnAssign_Click(object sender, EventArgs e)
        {
            SmartSpace.Core.Page selectedPage = null;
            ICoreService service = ServiceLocator.Get<ICoreService>();
            foreach (RepeaterItem item in _ctlList.Items)
            {
                CheckBox checkBox = (CheckBox)item.FindControl("_ctlCheck");
                if (checkBox != null && checkBox.Checked)
                {
                    HiddenField hiddenField = (HiddenField)item.FindControl("_ctlTag");
                    Guid pageId = new Guid(hiddenField.Value);
                    selectedPage = service.GetPage(SsSite.Current.Id, pageId);
                    break;
                }
            }

            if (selectedPage != null)
            {
                SsPage.Return(this, new { id = selectedPage.Id, code = selectedPage.Code, caption = selectedPage.Caption, type = selectedPage.Type, url = selectedPage.Url });
            }
        }

        protected void _ctlBtnSearch_Click(object sender, EventArgs e)
        {
            ICoreService service = ServiceLocator.Get<ICoreService>();
            PagedList<SmartSpace.Core.Page> pages = service.GetPages(SsSite.Current.Id, 0, 999);
            _ctlList.DataSource = pages;
            _ctlList.DataBind();
        }
    }
}